package cn.wolfcode.crm.service.impl;

import cn.wolfcode.crm.domain.CustomerTransfer;
import cn.wolfcode.crm.mapper.CustomerMapper;
import cn.wolfcode.crm.mapper.CustomerTransferMapper;
import cn.wolfcode.crm.query.PageResult;
import cn.wolfcode.crm.query.QueryObject;
import cn.wolfcode.crm.service.ICustomerTransferService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

//使用IOC的注解告诉SPring来帮我们管理当前对象
@Service
public class CustomerTransferServiceImpl implements ICustomerTransferService {
    @Autowired//自动注入
    private CustomerTransferMapper mapper;

    @Autowired
    private CustomerMapper customerMapper;

    @Override
    public void save(CustomerTransfer transfer) {
        //保存历史信息
        mapper.insert(transfer);

        //将客户的营销人员修改为新的营销update customer set seller_id = ? where id = ?
        customerMapper.updateSellerId(transfer.getNewseller().getId(), transfer.getCustomer().getId());
    }


    @Override
    public PageResult query(QueryObject qo) {
        //封装用户需要的数据
        int count = mapper.selectForCount(qo);
        List<CustomerTransfer> list = mapper.selectForList(qo);

        //将用户需要的所有的数据封装起来
        return new PageResult(list, count, qo.getCurrentPage(), qo.getPageSize());
    }


}
